#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>


//int main()
//{
//  printf("testexec ... begin!\n");
//
//  execl("/usr/bin/ls","ls","-l","-a",NULL);   //进程替换成功,当前程序后续代码被替换，不再运行
//  //execl("/usr/bin/lsss","lsss","-l","-a",NULL);  //替换失败,后续代码继续运行
//  
//  printf("testexec ... end!\n");
//  
//  return 0;
//}

/////////////////////////////////////////////////////////////////////////////////////////////////
// 子进替换

int main()
{
  printf("testexec ... begin!\n");
  
  pid_t id=fork();
  if(id==0)
  {
    //child
    
    sleep(2);

    //execl("/usr/bin/lsss","lsss","-l","-a",NULL);
    //execl("/usr/bin/ls","ls","-l","-a",NULL);
    
   //execlp("ls","ls","-l","-a",NULL);
    
   // char *const argv[]=
   // {
   //   (char*)"ls",
   //   (char*)"-l",
   //   (char*)"-a",
   //   (char*)"--color",
   //   NULL
   // };
   // //execv("/usr/bin/ls",argv);
   // execvp("ls",argv);
    
    
    exit(1);
  }

  //father
  int status=0;
  pid_t rid=waitpid(id,&status,0);
  if(rid>0)
  {
    printf("father wait success,child exit code:%d\n",WEXITSTATUS(status));
  }
  
  printf("testexec ... end!\n");
  
  return 0;
}
